package pro.cherish.demojunit.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;

import java.util.Map;
import java.util.UUID;

/**
 * spring环境变量初始化完成事件监听
 *
 * @Description spring环境变量初始化完成事件监听
 * @ClassName EnvPreparedListener
 * @Author lwh
 * @Date 2020/3/23 17:54
 * @Version 1.0
 */
@Slf4j
public class EnvironmentPreparedListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
	@Override
	public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
		Map<String, Object> env = event.getEnvironment().getSystemProperties();
		//instanceId
		env.put("instanceId", UUID.randomUUID().toString().replace("-", ""));
		System.out.println("环境变量准备完成");
	}
}
